define(['./../initial', './../service/showMsg'], function() {
    var app = angular.module('App.home');
    app.factory('Corporation', ['$rootScope', '$filter', "$http", "$q",
        function($rootScope, $filter, $http, $q) {

            var Corporation = function() {
                this.name = "";
                this.departments = [];
            };

            Corporation.corporationList = [];


            Corporation.getCorporationList = function() {
                var defer = $q.defer();
                if (Corporation.corporationList.length > 0) {
                    defer.resovle(Corporation.corporationList);
                } else {
                    $http({
                        method: 'get',
                        url: "/register2/corporation"
                    }).success(function(data) {
                        data.forEach(function(item, index) {
                            data[index] = angular.extend(new Corporation(), item);
                        });
                        defer.resolve(data);
                    });
                }
                return defer.promise;
            };

            return Corporation;
        }
    ]);
});
